package com.woniuxy.boss.bossassembly.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.woniu.form.AdminForm;
import com.woniuxy.boss.bossassembly.model.BaAdmin;
import com.woniuxy.boss.bossassembly.dao.BaAdminMapper;
import com.woniuxy.boss.bossassembly.service.IBaAdminService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 后台用户表 服务实现类
 * </p>
 *
 * @author HDC
 * @since 2021-05-24
 */
@Service
@Slf4j
public class BaAdminServiceImpl extends ServiceImpl<BaAdminMapper, BaAdmin> implements IBaAdminService {
    @Autowired
    private BaAdminMapper baAdminMapper;
    @Override
    public Integer addAdmin(AdminForm adminForm) {
        BaAdmin baAdmin = new BaAdmin();
        log.info("Service传入用户{}", adminForm.getAdminName());
        baAdmin.setAdminName(adminForm.getAdminName());
        baAdmin.setAdminPassword(adminForm.getAdminPassword());
        baAdmin.setAdminUsername(adminForm.getAdminUsername());
        baAdmin.setRawAddTime(new Date());
        baAdmin.setRawUpdateTime(new Date());
        baAdminMapper.insert(baAdmin);
        return baAdminMapper.insert(baAdmin);
    }

    @Override
    public Integer deleteAdmin(Integer adminId){
        log.info("Service传入用户ID{}", adminId);
        return baAdminMapper.deleteById(adminId);
    }

    @Override
    public Integer updateAdmin(AdminForm adminForm) {
        log.info("Service传入用户Form{}", adminForm);
        BaAdmin baAdmin = baAdminMapper.selectById(adminForm.getAdminId());
        baAdmin.setAdminName(adminForm.getAdminName());
        baAdmin.setAdminPassword(adminForm.getAdminPassword());
        baAdmin.setAdminUsername(adminForm.getAdminUsername());
        UpdateWrapper Wrapper = new UpdateWrapper<>();
        Wrapper.eq("admin_id",adminForm.getAdminId());
        baAdminMapper.update(baAdmin,Wrapper);
        return null;
    }

    @Override
    public List getAllAdmin() {
        log.info("Service查询用户");
        List<BaAdmin> baAdmins = baAdminMapper.selectList(null);
        return baAdmins;
    }
}
